package com.gcsoftware.web.controller;

import com.gcsoftware.web.service.T_COM_SYS_LOGSERVICE;
import com.gcsoftware.web.beans.T_COM_SYS_LOGS;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by qs on 2018/3/25.
 */
@Controller
@RequestMapping("/logs")
public class SysLogController {
    @Autowired
    private T_COM_SYS_LOGSERVICE logService;

    @ResponseBody
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public List<T_COM_SYS_LOGS> queryLoginLogs(
            @RequestParam(value = "c_LOGIN_NAME" , required = false) String c_LOGIN_NAME,
            @RequestParam(value = "c_START_TIME" , required = false) String c_START_TIME,
            @RequestParam(value = "c_END_TIME" , required = false) String c_END_TIME
                                               ) {
        if ("".equals(c_LOGIN_NAME)) {
            c_LOGIN_NAME = null;
        }
        if(StringUtils.isNotBlank(c_START_TIME)) {
            c_START_TIME = c_START_TIME + " 00:00:00";
        } else {
            c_START_TIME = null;
        }

        if(StringUtils.isNotBlank(c_END_TIME)) {
            c_END_TIME += " 23:59:59.999";
        } else {
            c_END_TIME = null;
        }
        return logService.queryLoginLogs(c_LOGIN_NAME, c_START_TIME, c_END_TIME);
    }

    @ResponseBody
    @RequestMapping(value = "/{c_LOG_ID}/opr-list",method = RequestMethod.POST)
    public List<T_COM_SYS_LOGS> queryOprLogs(@PathVariable(value = "c_LOG_ID" , required = true) String c_LOG_ID) {
        return logService.queryOprLogs(c_LOG_ID);
    }
}
